<?php
namespace app\home\controller;
use think\Controller;

use app\common\model\Member;

class Index extends Controller
{
    public $is_close = 0;

    public function _initialize(){
        // 系统关闭
        $is_close = model('option')::getOne('home_close');
        $this->is_close = $is_close;
    }

    public function index()
    {
        if($this->is_close==1){
            $this->redirect('close');
            exit();
        }

        $this->redirect('main/index');
    }

    public function logpage(){

        if($this->is_close==1){
            $this->redirect('close');
            exit();
        }

    	// 页面信息
        $pageData = ['title'=>'会员登录'];

        $this->assign('pageData',$pageData);
        return view();
    }

    public function login(){

        if($this->is_close==1){
            $this->redirect('close');
            exit();
        }

    	$params = $this->request->post();

    	$validate = $this->validate($params,'Login.home_login');
    	if(true!==$validate){
    		$this->error($validate);
    	}

        $loginname = $params['loginname'];
        $password = $params['password'];

    	$member=model('member')->getLoginMember($loginname);

        if(password_verify($password,$member['password'])){
            session('member',$member);
            $this->success('登录成功');
        }else{
            $this->error('密码错误');
        }
        
    }

    public function logout(){
    	session('member',null);
        $this->redirect('index/logpage');
    }

    public function close(){

        if($this->is_close==0){
            $this->redirect('index');
            exit();
        }

        // 页面信息
        $pageData = ['title'=>'系统关闭'];
        $tip = \app\common\query\Option::get('home_close_tip');

        $this->assign('pageData',$pageData);
        $this->assign('tip',$tip);
        return view();
    }

}
